package nix.bs.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nix.bs.domain.Order;
import nix.bs.service.OrderService;
import nix.servlet.BaseServlet;

public class AdminOrderServlet extends BaseServlet {

	private OrderService orderService = new OrderService();

	/**
	 * 确认发货
	 */	
	public String findAll(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		List<Order> orderList = orderService.findAll();
		request.setAttribute("orderList", orderList);
		return "f:/bs/adminjsps/admin/order/list.jsp";
	}

	/**
	 * 按状态查询
	 */	
	public String findByState(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		int state = Integer.parseInt(request.getParameter("state"));
		List<Order> orderList = orderService.findByState(state);
		request.setAttribute("orderList", orderList);
		return "f:/bs/adminjsps/admin/order/list.jsp";
	}
	
	
	/**
	 * 确认发货
	 */
	public String deliver(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String oid = request.getParameter("oid");
		try {
			orderService.deliver(oid);
			return findAll(request, response);
		} catch (Exception e) {
			request.setAttribute("msg", e.getMessage());
			return "f:/bs/jsps/msg.jsp";
		}
	}
}
